export const user = {
    namespaced: true,
    state: {
        name: '老六',
        gender: '女',
        age: 16,
        profession: '前端开发工程师'
    },
    getters: {
        getUserInfo: state => {
            return state.name + '的职业是' + state.profession
        },
        getUserSex: state => {
            return state.name + '的年龄是' + state.age
        }
    },
    mutations: {
        addAge: state => { // 模块内部的action和mutation仍然注册在全局命名空间，多个模块能够对同一个action或者mutation做出响应
            state.age++
        },
        addAgeLoad: (state, payload) => {
            state.age += payload
        }
    },
    actions: {
        addAgeAction (context) {
            console.log(context)
            context.commit('addAge')
        },
        addAgeLoadAction (context, payload) {
            // context上下文对象， 可以 理解为store对象
            console.log(context.commit)
            console.log(payload)
            context.commit('addAgeLoad', payload)
        }
    }
}
